package org.ghost.wechat.platform.dao;

import feign.Response;
import org.ghost.wechat.platform.config.feign.FeignCommonConfig;
import org.ghost.wechat.platform.dto.wechat.media.WeChatUploadMediaRspDTO;
import org.ghost.wechat.platform.dto.wechat.media.WeChatVideoUrlRspDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author 01
 * https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html
 */
@FeignClient(url = "https://api.weixin.qq.com", configuration = FeignCommonConfig.class)
public interface IWeChatMediaDAO {
    /**
     * 本接口获取临时素材（即下载临时的多媒体文件）。请注意，视频文件不支持https下载，调用该接口需http协议。
     * https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html
     *
     * @param accessToken 调用接口凭据
     * @param mediaId     媒体文件ID
     * @return
     */
    @GetMapping(name = "cgi-bin/media/get")
    Response getTempMedia(@RequestParam(value = "access_token") String accessToken, @RequestParam(value = "media_id") String mediaId);

    /**
     * 高清语音素材获取接口
     * 公众号可以使用本接口获取从JSSDK的uploadVoice接口上传的临时语音素材，格式为speex，16K采样率。该音频比上文的临时素材获取接口（格式为amr，8K采样率）更加清晰，适合用作语音识别等对音质要求较高的业务。
     * https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html
     *
     * @param accessToken 调用接口凭据
     * @param mediaId     媒体文件ID，即uploadVoice接口返回的serverID
     * @return
     */
    @GetMapping(name = "cgi-bin/media/get/jssdk")
    Response getTempHighDefinitionVoice(@RequestParam(value = "access_token") String accessToken, @RequestParam(value = "media_id") String mediaId);

    /**
     * 获取视频现在链接
     * https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Get_temporary_materials.html
     *
     * @param accessToken 调用接口凭据
     * @param mediaId     媒体文件ID
     * @return
     */
    @GetMapping(name = "http://api.weixin.qq.com/cgi-bin/media/get")
    WeChatVideoUrlRspDTO getVideoUrl(@RequestParam(value = "access_token") String accessToken, @RequestParam(value = "media_id") String mediaId);

    /**
     * 上传临时素材
     * https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html
     *
     * @param accessToken 调用接口凭据
     * @param type        媒体文件类型，分别有图片（image）、语音（voice）、视频（video）和缩略图（thumb）
     * @param media       form-data中媒体文件标识，有filename、filelength、content-type等信息
     * @return
     */
    @PostMapping(value = "cgi-bin/media/upload", produces = {MediaType.APPLICATION_JSON_UTF8_VALUE}, consumes = {MediaType.MULTIPART_FORM_DATA_VALUE})
    WeChatUploadMediaRspDTO uploadTempMedia(@RequestParam(value = "access_token") String accessToken, @RequestParam(value = "type") String type, @RequestPart(value = "media") MultipartFile media);
}
